package com.yc.cloudvideo.sp_store.mapper;

import com.yc.cloudvideo.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.cloudvideo.entity.File;
import com.yc.cloudvideo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LYYT
 * @since 2022-08-03
 */
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("select * from comment where cid=#{cid} and parentid is null order by likenum desc limit #{begin},#{size}")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",
                    one = @One(select = "com.yc.cloudvideo.sp_store.mapper.UserMapper.selectUserByUid"))
    })
    List<Comment> selectCommentByLikenum(long cid,int begin,int size);

    @Select("select * from comment where cid=#{cid} and parentid is null order by talk_time desc limit #{begin},#{size}")
    @Results({
            @Result(property = "uid",column = "uid"),
            @Result(property = "user",column = "uid",
                    one = @One(select = "com.yc.cloudvideo.sp_store.mapper.UserMapper.selectUserByUid"))
    })
    List<Comment> selectCommentByCidDesc(long cid,int begin,int size);

    @Select("select * from comment where parentid=#{parentid} order by talk_time desc")
    @Results({
            @Result(property = "parentid",column = "parentid"),
            @Result(property = "user",column = "uid",
                    one = @One(select = "com.yc.cloudvideo.sp_store.mapper.UserMapper.selectUserByUid"))
    })
    List<Comment> selectCommentSon(long parentid);

    @Select("select count(*) from comment where cid=#{cid} and parentid is null order by talk_time desc")
    int selectCommentCount(long cid);

    @Select("select count(*) from comment where parentid=#{pid}")
    long selectCommentReply(long pid);


}
